package com.project.listen;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.UUID;

@Component
public class DemoListener {

    private static final Logger logger= LoggerFactory.getLogger(DemoListener.class);

    //声明consumerID为demo，监听topicName为topic.quick.demo的Topic
    /*@KafkaListener(id = "demo", topics = "spring")
    public void listen(String msgData) {
        log.info("demo receive : "+msgData);
    }*/

    @KafkaListener(id = "QRC", topics = "01QRC", idIsGroup = false, groupId = "QRC")
    public void consumer1(ConsumerRecord<String, String> consumerRecord) {
        String logId = UUID.randomUUID().toString().replaceAll("-", "");

        logger.info(consumerRecord.value());

    }

    @KafkaListener(id = "ACP", topics = "01ACP", idIsGroup = false, groupId = "ACP")
    public void consumer2(ConsumerRecord<String, String> consumerRecord) {
        String logId = UUID.randomUUID().toString().replaceAll("-", "");

        System.out.println(consumerRecord.value());
        logger.info(consumerRecord.value());
    }

    @KafkaListener(id = "CUPS", topics = "01CUPS", idIsGroup = false, groupId = "CUPS")
    public void consumer3(ConsumerRecord<String, String> consumerRecord) {
        String logId = UUID.randomUUID().toString().replaceAll("-", "");

        logger.info(consumerRecord.value());

    }
}
